package com.pos.clothes.service.serviceImpl;

import com.pos.clothes.mapper.CategoryMapper;
import com.pos.clothes.mapper.ClothesMapper;
import com.pos.clothes.mapper.OrderMapper;
import com.pos.clothes.pojo.Category;
import com.pos.clothes.pojo.Order;
import com.pos.clothes.pojo.Order_detail;
import com.pos.clothes.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private OrderMapper ordermapper;
    @Autowired
    private CategoryMapper categorymapper;
    @Override
    public  double[]  getAllOrderAboutDate(String s) {

//        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM");
//        String now=simpleDateFormat.format(new Date());
        Calendar c = Calendar.getInstance();
        List<Order> list = ordermapper.getAllOrderaboutDate(s);
        double[] en = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                        0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                        0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                        0.0};
        int len = en.length;
        for(Order order : list){
            c.setTime(order.getTime());
            int day = c.get(Calendar.DAY_OF_MONTH);
            en[day-1] = en[day-1] + order.getTotal();
        }
        return en;

    }

    @Override
    public double[] getALLOrderAboutMonth(String s) {
        Calendar c = Calendar.getInstance();
        List<Order> list = ordermapper.getAllOrderaboutDate(s);
        double[] en = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
               0.0,0.0};
        int len = en.length;
        for(Order order : list){
            c.setTime(order.getTime());
            int month = c.get(Calendar.MONTH);
            en[month] = en[month] + order.getTotal();
        }
        return en;

    }

    @Override
    public HashMap<String,Integer> getCategoryInsituation() {
        HashMap map = new HashMap<String, Integer>();
        for(Category category:categorymapper.getCategory()){
            map.put(category.getCategory_name(),0);
        }
        for(Order order: ordermapper.getOrderDetailaboutDate()){
            for(Order_detail order_detail :order.getOrder_detail()){
                Category category = order_detail.getNorms().getClothes().getCategory();
                map.put(category.getCategory_name(),Integer.valueOf((Integer) map.get(category.getCategory_name()))+order_detail.getNumber());
            }
        }
    return map;
    }

}
